<template>
    <l-dialog :visible.sync="formVisible" :height="700" :width="1200" @close="handleCloseForm" @opened="handleOpenedForm"
        :hasBtns="true" :showMinBtn="false" :showFullscreenBtn="false" ref="lrDialog">
        <template #title>
            <h3>{{ }}</h3>
        </template>
        <template>
            <h4>用地信息</h4>
            <el-form :model="landFormData" :rules="rules" size="mini" labelPosition="top" labelWidth="110px" ref="landForm">
                <l-custom-form ref="landCustomForm" :span="6" :columns="landColumns" :formData="landFormData" />
            </el-form>
        </template>
        <template>
            <h4>地块历年亩均税收</h4>
            <revenueTable :landFormData="landFormData" :options="options" />
        </template>
        <template>
            <h4>入驻企业</h4>
            <residentEnterpriseForm :landFormData="landFormData" :options="options" />
        </template>
        <template #btns>
            <el-button size="small" @click="handleCancel">取消</el-button>
            <el-button size="small" type="primary" @click="handleCommit">提交</el-button>
        </template>
    </l-dialog>
</template>

<script>
import {
    landFormData,
    landColumns,
    revenueTableColmuns,
    dynApi,
} from "./columns";
import revenueTable from "./revenueTable";
import residentEnterpriseForm from "./residentEnterpriseForm";
export default {
    components: {
        revenueTable,
        residentEnterpriseForm,
    },
    props: {
        formEdit: {
            type: Boolean,
            default: true,
        },
    },
    data() {
        return {
            formVisible: false,
            landFormData: landFormData,
            landColumns,
            revenueTableColmuns,
            dynApi,
            options: {},
            rules: {
                name: [{ required: true, message: "请输入内容", trigger: "blur" }],
            },
            labelIdList: [],
        };
    },
    computed: {
        typesOptions() {
            return this.lr_dataItemOptions(this.lr_dataItem["types"]);
        },
    },
    mounted() {
        // 
    },
    methods: {
        open(row = {}, options = {}) {
            this.options = options;
            this.landFormData = Object.assign({}, landFormData, row);
            // 立软l-dialog组件 isfullscreen 的监视属性，控制全屏
            this.$refs.lrDialog.isfullscreen = true;
            this.$refs.lrDialog.onMousedown = function () { }
            this.formVisible = true;
            this.$nextTick(() => {
                this.$refs.landForm.clearValidate();
            });
        },
        handleCancel() {
            this.formVisible = false;
        },
        handleCommit() {
            this.$refs["landForm"].validate(async (valid) => {
                if (valid) {
                    const {
                        name,
                        regionCode,
                        address,
                        evaluationPrice,
                        coverArea,
                        existingUnfinishedLand,
                        existingUnfinishedReason,
                        originalBuildingArea,
                        originalPlotRatio,
                        industrialUpdateCode,
                        updatedLandPropertiesCode,
                        updatedBuildingArea,
                        updatedPlotRatio,
                        landUseTypeCode,
                        industrialUpdateDemolitionArea,
                        industrialUpdateNewArea,
                        datasourceCode,
                        updateCycleCode,
                        landcertificate,
                        ownershipCertificate,
                        preUpdatePhoto,
                        updatedPhoto,
                        originalLandPropertiesCode,
                        industrialUpdateCost,
                    } = this.$refs.landCustomForm.formData;
                    this.landFormData.landInfo = {
                        name,
                        regionCode,
                        address,
                        evaluationPrice,
                        coverArea,
                        existingUnfinishedLand,
                        existingUnfinishedReason,
                        originalBuildingArea,
                        originalPlotRatio,
                        industrialUpdateCode,
                        updatedLandPropertiesCode,
                        updatedBuildingArea,
                        updatedPlotRatio,
                        landUseTypeCode,
                        industrialUpdateDemolitionArea,
                        industrialUpdateNewArea,
                        datasourceCode,
                        updateCycleCode,
                        landcertificate,
                        ownershipCertificate,
                        preUpdatePhoto,
                        updatedPhoto,
                        originalLandPropertiesCode,
                        industrialUpdateCost,
                    };
                    this.landFormData.companys = [{

                    }]
                    this.landFormData.landMuTaxs = [{

                    }]
                    if (this.landFormData.id) { // 修改

                        let res = await this.dynApi.update(
                            this.landFormData.id,
                            this.landFormData
                        );
                        if (res.data.code === 200) {
                            this.$message({
                                type: "success",
                                message: "修改成功",
                            });
                            this.refresh();
                            this.formVisible = false;
                        } else {
                            this.$message({
                                type: "error",
                                message: "修改失败",
                            });
                        }
                    } else { // 新增
                        let res = await this.dynApi.add(this.landFormData);
                        if (res.data.code === 200) {
                            this.$message({
                                type: "success",
                                message: '新增成功'
                            });
                            this.refresh();
                            this.formVisible = false;
                        } else {
                            this.$message({
                                type: "error",
                                message: "新增失败"
                            })
                        }
                    }
                } else {
                    this.$message({
                        type: "error",
                        message: "您有必填项没有填写",
                    });
                    return false;
                }
            });
        },
        async handleOpenedForm(showLoading, hideLoading) {
            if (this.formEdit) {
                showLoading("加载数据中...");
                hideLoading();
            }
        },
        refresh() {
            this.$emit("refresh");
        },
        handleCloseForm() {
            this.formVisible = false;
        },
    },
};
</script>
<style lang="scss" scoped>
.header {
    width: 100%;
}

::v-deep .el-dialog__body {
    padding: 10px;
}

.dialog-container {
    overflow: auto;
}

.el-icon-upload-success.el-icon-circle-check {}
</style>
